import { create } from "zustand";
import { changeLan, checkI18nStore } from '@/utils/i18n'

const init = checkI18nStore()

type State = {
  language: 'zh' | 'en';
}

type Action = {
  setLanguage: (language: State['language']) => void;
  getLanguage: () => State['language'];
}

const useLanguageStore = create<State & Action>((set, get) => ({
  language: init || 'zh',
  setLanguage: (language) => {
    console.log(language)
    set(() => ({ language }))
    changeLan(language)
  },
  getLanguage: () => get().language,
}))

export default useLanguageStore;